/**
 * Copyright (c) 2018-2028, Joffee.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sailmi.system.controller;

import com.sailmi.common.controller.BaseController;
import com.sailmi.common.mybatis.support.Condition;
import com.sailmi.common.mybatis.support.Query;
import com.sailmi.common.tool.api.R;
import com.sailmi.common.tool.utils.Func;
import com.sailmi.system.entity.ServiceMenu;
import com.sailmi.system.service.IServiceMenuService;
import com.sailmi.system.vo.ServiceMenuVO;
import com.sailmi.system.wrapper.ServiceMenuWrapper;
import javax.validation.Valid;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能 控制器
 *
 * @author sailmi
 * @since 2020-09-17
 */
@RestController
@RequestMapping("/servicemenu")
@Tag(name = "服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能", description = "服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能接口")
public class ServiceMenuController extends BaseController {

	private final IServiceMenuService serviceMenuService;

	public ServiceMenuController(IServiceMenuService serviceMenuService) {
		this.serviceMenuService = serviceMenuService;
	}

	/**
	* 详情
	*/
	@GetMapping("/detail")
	@Operation(summary = "详情", description = "传入serviceMenu")
	public R<ServiceMenuVO> detail(ServiceMenu serviceMenu) {
		ServiceMenu detail = serviceMenuService.getOne(Condition.getQueryWrapper(serviceMenu));
		return R.data(ServiceMenuWrapper.build().entityVO(detail));
	}

	/**
	* 分页 服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能
	*/
	@GetMapping("/list")
	@Operation(summary = "分页", description = "传入serviceMenu")
	public R<IPage<ServiceMenuVO>> list(ServiceMenu serviceMenu, Query query) {
		IPage<ServiceMenu> pages = serviceMenuService.page(Condition.getPage(query), Condition.getQueryWrapper(serviceMenu));
		return R.data(ServiceMenuWrapper.build().pageVO(pages));
	}

	/**
	* 自定义分页 服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能
	*/
	@GetMapping("/page")
	@Operation(summary = "分页", description = "传入serviceMenu")
	public R<IPage<ServiceMenuVO>> page(ServiceMenuVO serviceMenu, Query query) {
		IPage<ServiceMenuVO> pages = serviceMenuService.selectServiceMenuPage(Condition.getPage(query), serviceMenu);
		return R.data(pages);
	}

	/**
	* 新增 服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能
	*/
	@PostMapping("/save")
	@Operation(summary = "新增", description = "传入serviceMenu")
	public R save(@Valid @RequestBody ServiceMenu serviceMenu) {
		return R.status(serviceMenuService.save(serviceMenu));
	}

	/**
	* 修改 服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能
	*/
	@PostMapping("/update")
	@Operation(summary = "修改", description = "传入serviceMenu")
	public R update(@Valid @RequestBody ServiceMenu serviceMenu) {
		return R.status(serviceMenuService.updateById(serviceMenu));
	}

	/**
	* 新增或修改 服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能
	*/
	@PostMapping("/submit")
	@Operation(summary = "新增或修改", description = "传入serviceMenu")
	public R submit(@Valid @RequestBody ServiceMenu serviceMenu) {
		return R.status(serviceMenuService.saveOrUpdate(serviceMenu));
	}


	/**
	* 删除 服务功能包设定，表明此功能属于哪个服务包，只有享受此服务包的用户才能访问这个功能
	*/
	@PostMapping("/remove")
	@Operation(summary = "删除", description = "传入ids")
	public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
		return R.status(serviceMenuService.removeByIds(Func.toLongList(ids)));
	}


}
